home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / mus / play / tracker_4_31.lzh / tracker / Arch / Aix / audio.c next >
C/C++ Source or Header  |  1995-02-24  |  3KB  |  172 lines

  1. /* Aix/audio.c 
  2.     vi:ts=3 sw=3:
  3.  */
  4. /* Ported from Linux/audio.c by Sam Hartman <hartmans@mit.edu>*/
  5. /* minor mods for pl14 by Mike Battersby */
  6. /* Modified from soundblaster_audio.c by Hannu Savolainen */
  7. /* hsavolai@cs.helsinki.fi */
  8.  
  9. #include "defs.h"
  10. #include <unistd.h>
  11. #include <fcntl.h>
  12. #include "extern.h"
  13.  
  14. #undef SIGNED /*redefined in system include file*/
  15. #include <sys/audio.h>
  16. #include <sys/acpa.h>
  17.  
  18.  
  19. ID("$Id: audio.c,v 1.8 1995/02/24 13:48:39 espie Exp espie $")
  20.  
  21. #define UNSIGNED_BUFFERS
  22. #define DEFAULT_SET_MIX
  23. #define DEFAULT_BUFFERS
  24. #define NEW_OUTPUT_SAMPLES_AWARE
  25.  
  26. #include "Arch/common.c"
  27.  
  28. LOCAL int buf_max;
  29. LOCAL int audio;               /* /dev/acpa0/1 */
  30.  
  31. LOCAL int dsp_samplesize = 16; /* must be 8 or 16 */
  32.  
  33. int open_audio(f, s)
  34. int f;
  35. int s;
  36.       {
  37.       audio_init init;
  38.     audio_control control;
  39.     audio_change change;
  40.     audio = open("/dev/acpa0/1", O_WRONLY, 0);
  41.    if (audio == -1)
  42.         end_all("Error opening audio device");
  43.  
  44.     if (f==0) f = 44100;
  45.  
  46.    init.srate = f;
  47.    init.bits_per_sample = 16;
  48.    init.mode = PCM;
  49.     init.channels = s?2:1;
  50.    init.flags = BIG_ENDIAN;
  51.     init.operation = PLAY;
  52.    if (ioctl(audio, AUDIO_INIT, &init)!= 0)
  53.         end_all("Error initializing ACPA");
  54.  
  55.     stereo = (init.channels == 2)?1:0;
  56.     buf_max = init.bsize*20;    /* This is set by the ioctl. */
  57.  
  58.    buffer = malloc(buf_max);
  59.    buffer16 = (short *)buffer;
  60.    idx = 0;
  61.     switch(dsp_samplesize)
  62.         {
  63.     case 16:
  64.         dsize = 2;
  65.         break;
  66.     case 8:
  67.         dsize = 1;
  68.         break;
  69.     default:
  70.         end_all("Error: unknown sample size");
  71.         }
  72.     
  73.     samples_max = buf_max/dsize;
  74.  
  75.    control.ioctl_request = AUDIO_CHANGE;
  76.     control.request_info = &change;
  77.     control.position = 0;
  78.  
  79.     change.dev_info = 0;
  80.     change.input = AUDIO_IGNORE;
  81.     change.output = OUTPUT_1;
  82.     change.monitor = AUDIO_IGNORE;
  83.     change.volume = 0x7fff0000;
  84.     change.volume_delay = 0;
  85.     change.balance = 0x3fff0000;
  86.     change.balance_delay = 0;
  87.     change.treble = AUDIO_IGNORE;
  88.     change.bass = AUDIO_IGNORE;
  89.     change.pitch = AUDIO_IGNORE;
  90.     
  91.     if (ioctl(audio, AUDIO_CONTROL, &control) != 0)
  92.         end_all( "Error changing ACPA parameters");
  93.  
  94.     control.ioctl_request = AUDIO_START;
  95.  
  96.       if (ioctl(audio, AUDIO_CONTROL, &control) != 0)
  97.         end_all("Error starting ACPA");
  98.  
  99.       return init.srate;
  100.  
  101.    }
  102.  
  103. LOCAL void actually_flush_buffer()
  104.    {
  105.    write(audio, buffer, dsize * idx);
  106.    idx = 0;
  107.    }
  108.  
  109. void output_samples(left, right, n)
  110. int left, right, n;
  111.    {
  112.     if (idx >= samples_max - 1)
  113.         actually_flush_buffer();
  114.  
  115.     switch(dsp_samplesize)
  116.         {
  117.     case 16:     /* Cool! 16 bits/sample */
  118.         add_samples16(left, right, n);
  119.         break;
  120.     case 8:
  121.         add_samples8(left, right, n);
  122.         break;
  123.     default:
  124.        }
  125.     }
  126.  
  127. void flush_buffer()
  128.    {    /* Dummy version */
  129.    }
  130.  
  131. /* We must wait for all samples to be played before closing.*/
  132. void close_audio()
  133.    {
  134.    audio_control control;
  135.    if (idx != 0)
  136.         actually_flush_buffer();
  137.    ioctl(audio, AUDIO_WAIT, 0);
  138.    control.position = 0;
  139.     control.ioctl_request = AUDIO_STOP;
  140.     control.request_info = 0;
  141.     ioctl(audio, AUDIO_CONTROL, &control);
  142.  
  143.    close(audio);
  144.    free(buffer);
  145.    }
  146.  
  147. /* dummy system calls, to patch ? */
  148. void set_synchro(s)
  149.     {
  150.     }
  151.  
  152. int update_frequency()
  153.     {
  154.     return 0;
  155.     }
  156.  
  157. void discard_buffer()
  158.     {
  159.    audio_control control;
  160.    control.ioctl_request = AUDIO_STOP;
  161.     control.request_info = 0;
  162.     control.position = 0;
  163.     ioctl(audio, AUDIO_CONTROL, &control);
  164.    usleep(150000);
  165.    control.ioctl_request = AUDIO_START;
  166.    if (ioctl(audio, AUDIO_CONTROL, &control) == -1)
  167.         end_all ("Unable to restart AACPA");
  168.     idx = 0;
  169.     }
  170.  
  171.  
  172.